
<script type="text/javascript">
<!--
	$(function(){
		$(".button").button();

		$("#news_check").toggle(
			function () {
				$("input:checkbox").attr("checked",true);
				$(this).attr("checked",true);
			},
			function () {
				$("input:checkbox").attr("checked",false);
				$(this).attr("checked",false);
			}
		);
			


		load();		

		$(".portlet-title").click(function(){
//			event.preventDefault();
			return false;
		});
		
	});

	function hoverItem(object){

		object.find(".new-item-action").show();

	}
	
	function mouseOut(object){
		object.find(".new-item-action").hide();
	}

	//Note:此处两相参数，第一个为当前URL中的相关参数，第二个则为指定参数
	function getVal(object1,object2){
		if(object1.val()!='' && object2.val()==''){
			return object1.val();
		}else if(object1.val() == '' && object2.val() != ''){
			return object2.val();
		}else{
			return object2.val();
		}
	}

	function load(){
/*		$.post('<?php echo $this->createUrl('listdetail');?>',function(msg){
			$("#news-list").html(msg);
		});
*/    
        var cate = getVal($("#category"),$("#news_category"));
        var state = getVal($("#state"),$("#news_state"));
        var ctype = $("#ctype").val();
        var page = getVal($("#page"),$("#news_page"));
		
        
        var url = $(".yiiPager").find(".selected").find("a").attr("href");
        
        if(url == undefined){
            url = "<?php echo $this->createUrl('listdetail')?>";
        }

        
        $.post(url,{'category':cate,'state':state,'page':page,'ctype':ctype},function(data){

           
           $("#news-list").html(data); 
        });
	}

	function checkAll(object){
		$("input[name=news_item]").each(function(i){
			if(object.attr("checked")==true){
				$(this).attr("checked",true);
			}else{
				$(this).attr("checked",false);
			}
		});
	}
	
	function getCheckedItems(){
		var str = '';
		$("input[name=news_item]").each(function(i){
//			$(this).attr("checked") = true;
			if($(this).attr("checked")==true){
				str += $(this).val();
			}
		});
		alert(str);
	}
    
    function actionUpdate(object){
        var src = object.attr("id");
      //  alert(src);
/*        $.get(url,{'r':Math.random()},function(data){
           alert(data);           

        });
*/      $.colorbox({iframe:true, width:"95%", height:"95%",href:src,onClosed:function(){ 
                load(); 
                $("#example7").click(); 
            }
        });
    }    

    function actionView(object){
        var src=object.attr('id');
       // alert(src);
        $.colorbox({iframe:true, width:"95%", height:"95%", href:src});
    }
    
    function actionTrash(object){    
        var src= object.attr("id");

       $.msgbox({
            height:100,
            width:250,
            content:{type:'confirm', content: '确认要把文章放入回收站吗？'},
            animation:4,
            onClose:function(v){
                if(v){
                       
                
                       $.post(src,{'ajax':1},function(data){
                            
                            if(data == "ok"){
                                object.parent().parent().parent().css({'background':'yellow'}).fadeOut();
                            }
                        });                   
                }
                
            }
        });       
        
     }
    
   	function func_update(id){
		var object = id.parent().siblings(".thumbnail");
		var src = id.attr("id");

		$.colorbox({iframe:true, innerWidth:425, innerHeight:444,href:src,onClosed:function(){ load(); }});
		
	}
    
    function actionSearch(){
        var cate = $("#news_category").val();
        var state = $("#news_state").val();
        var page = $("#news_page").val();
        
        $.post('<?php echo $this->createUrl('listdetail')?>',{'category':cate,'state':state,'page':page},function(data){
            
           $("#news-list").html(data); 
        });
    }    
    
    function getSelectedInfo(){
        var str = '';
        $("input[name='news_item']").each(function(i){
            if($(this).attr('checked') == true){
                str += ','+$(this).val();
            }
            
        });
        
        //str = str.substr(1,str.length());
        str = str.substring(1);
        arr = str.split(',');
        return arr;
    }
    function actionBatch(object){
 

         var ajax = 0;
         var arr = getSelectedInfo();
         len = arr.length;       

        if(arr[0] != ''){
             if(object.val() == 'delete'){
                
                 $.msgbox({
                    height:100,
                    width:250,
                    content:{type:'confirm', content: '确认要删除选中的文章吗？'},
                    animation:4,
                    onClose:function(v){
                        if(v){
                            

                            for(i in arr){
                                if(i == (len-1)){
                                    ajax = 1;
                                }
                                
                                
                                url = "<?php echo $this->createUrl('ajaxdelete'); ?>";
                                url = url.replace(/<?php echo Yii::app()->urlManager->urlSuffix;?>/,"/id/"+arr[i]+"<?php echo Yii::app()->urlManager->urlSuffix;?>");

                                $.post(url,{'ajax':ajax},function(data){
                                    
                                    if(data == 'ok'){
                                        $.msgbox({
                                           height:100,
                                           width:250,
                                           content:{type:'alert',content:'删除完毕！'},
                                           animation:4 
                                        });                                        
                                    }   
                                     
                                    $("#news_item"+arr[i]).parent().css({'background':'yellow'}).fadeOut();
                                    
                                    load();                 

                                    
                                });
                                
                            }                  
                        }
                    }
                 });
                
                
    
                
            }else if(object.val()=='trash'){
                
                
                 $.msgbox({
                    height:100,
                    width:250,
                    content:{type:'confirm', content: '确认要把选中的文章放回回收站吗？'},
                    animation:4,
                    onClose:function(v){
                        if(v){

                            for(i in arr){
                                if(i == (len-1)){
                                    ajax = 1;
                                }
                                
                                
                                url = "<?php echo $this->createUrl('ajaxtrash'); ?>";
                                url = url.replace(/.html/,"/id/"+arr[i]+".html");

                                $.post(url,{'ajax':ajax},function(data){
                                    
                                    if(data == 'ok'){
                                        $.msgbox({
                                           height:100,
                                           width:250,
                                           content:{type:'alert',content:'已经移动到回收站！'},
                                           animation:4 
                                        });                                        
                                    }   
                                     
                                    $("#news_item"+arr[i]).parent().css({'background':'yellow'}).fadeOut();
                                    
                                    load();                 

                                    
                                });
                                
                            } 
                        }
                    }
                 });
            }           
        }else{
            $.msgbox({
                'height':100,
                'width':250,
                'animation':4,
                content:{type:'alert',animate:4,content:'请选择要操作的文章！'}
            });
        }         
    }

//-->
</script>
<?php 
$news_category = CHtml::dropDownList('news_category','',UArray::arrayMerge(array(''=>'文章类别',),Category::model()->getCategoryDropdownList(Category::CATEGORY_NEWS)),array('onchange'=>'load();'));
$news_state = CHtml::dropDownList('news_state','',UArray::arrayMerge(array(''=>'文章状态',),Article::model()->generateStateDropdownList()),array('onchange'=>'load();'));

$page = isset($_GET['page'])?$_GET['page']:'';
$ctype = isset($_GET['ctype'])?$_GET['ctype']:'';
$state = isset($_GET['state'])?$_GET['state']:'';
$category = isset($_GET['id'])?$_GET['id']:'';

$html = <<<DOC
   <span>
    	&nbsp;&nbsp;
    	&nbsp;&nbsp;全选
    	<input type="checkbox" name="news_check" id="news_check" />
    	&nbsp;&nbsp;
    	{$news_category}
    	&nbsp;&nbsp;
    	{$news_state}	
    	&nbsp;&nbsp;
    	<select name="news_page" id="news_page" onchange="load();">
    		<option value="">每页显示条数</option>
    		<option value="5">5</option>
    		<option value="10" selected="selected">10</option>
    		<option value="15">15</option>
    		<option value="20">20</option>
    	</select>
    	&nbsp;&nbsp;
    	<select name="news_action" onchange="actionBatch($(this));">
    		<option value="">选择操作</option>
    		<option value="delete">删除</option>
    		<option value="trash">回收站</option>
    	</select>
    	<button id="action_submit" onclick="load();">确定操作</button>
    	<input type="hidden" id="page" value="{$page}" />
    	<input type="hidden" id="ctype" value="{$ctype}" />
    	<input type="hidden" id="state" value="{$state}" />
    	<input type="hidden" id="category" value="{$category}" />
    </span>
DOC;
?>
<?php $this->beginWidget('zii.widgets.CPortlet', array('title'=>CHtml::image($this->module->registerImage('article.png'),'Logo', array('width'=>'20'),array('htmlOptions'=>'class="dd"')).'&nbsp;&nbsp;文章列表'.$html,	));?>
<div class="box">
    <div class="box-title" style="height:30px;padding-top:5px;margin-top:5px;" onclick="event.preventDefault();">
    			<span style="width:2%;" class="left">&nbsp;</span>
    			<span style="width:38%; padding-left:10px;" class="left">
    				<?php echo Article::model()->getAttributeLabel('arc_title');?>
    			</span>
    			<span style="width:20%;" class="left">
    				<?php echo Article::model()->getAttributeLabel('arc_cid')?>
    			</span>
    			<span style="width:10%;" class="left">
    				<?php echo Article::model()->getAttributeLabel('arc_author');?>
    			</span>
    			<span style="width:10%;" class="left">
    				<?php echo Article::model()->getAttributeLabel('arc_iscomment');?>
    			</span>
    			<span style="width:10%;" class="left">
    				<?php echo Article::model()->getAttributeLabel('arc_created');?>
    			</span>		
    		
    </div>
    <div class="portlet-content box-content" id="news-list">
    
    </div>
</div>
<?php $this->endWidget();?>